<template>
	<div class="container">
		<el-form
			ref="ruleForm"
			:model="ruleForm"
			:rules="rules"
			label-suffix=":"
			label-width="240px"
			class="show-ruleForm"
		>
			<div class="btn-top-fixed" v-if="hasPermission('90150035')">
				<el-button
					v-if="disabled"
					type="primary"
					size="small"
					:disabled="loading"
					@click="handleEdit"
				>
					{{ $t('dxn.game_rule.edit_btn') }}
				</el-button>
				<div v-else>
					<el-button
						type="plain"
						size="small"
						:disabled="editLoading"
						@click="handleCancel"
					>
						{{ $t('dxn.game_rule.cancel_btn') }}
					</el-button>
					<el-button
						type="primary"
						size="small"
						:disabled="editLoading"
						:loading="editLoading"
						@click="handleSubmit"
					>
						{{ $t('dxn.game_rule.save_btn') }}
					</el-button>
				</div>
			</div>
			<div class="flex-box">
				<div class="left">
					<!-- 游戏ID -->
					<el-form-item
						:label="`${$t('dxn.game_rule.game_id')}`"
						prop="gameTypeId"
					>
						<el-input-number
							v-model.number="ruleForm.gameTypeId"
							:min="minDefault"
							:step="1"
							step-strictly
							:controls="false"
							disabled
						></el-input-number>
					</el-form-item>
					<!-- 玩法名称 -->
					<el-form-item
						:label="`${$t('dxn.game_rule.game_name')}`"
						prop="gameName"
					>
						<el-input
							v-model.trim="ruleForm.gameName"
							v-symbols
							clearable
							disabled
						></el-input>
					</el-form-item>
				</div>
			</div>
			<!-- 游戏总开关 -->
			<el-form-item
				:label="`${$t('dxn.game_rule.game_master_switch')}`"
				prop="status"
			>
				<el-switch
					:value="ruleForm.status"
					:disabled="!hasPermission('90150035')"
					active-color="#13ce66"
					:active-value="1"
					:inactive-value="0"
					@change="handleChangeStatus"
				></el-switch>
			</el-form-item>
			<!-- 超时(min)自动解散房间 -->
			<!-- :max="maxLimit.gameOvertime" -->
			<el-form-item
				:label="`${$t('dxn.game_rule.timeout')}`"
				prop="gameOvertime"
			>
				<el-input-number
					v-model.number="ruleForm.gameOvertime"
					:min="minDefault"
					:step="1"
					step-strictly
					:controls="false"
					:disabled="disabled"
					:placeholder="`${$t('dxn.game_rule.timeout_placeholder')}`"
					v-input="{ name: 'int' }"
				></el-input-number>

				<span style="padding-left:20px;font-size: 12px;color: #979797;">
					注：当前定时任务有五分钟误差
				</span>
			</el-form-item>
			<div class="show-panel">
				<span class="title" style="width: 80px;">盲注配置</span>
				<!-- 德州大盲BB 短牌Ante -->
				<el-form-item :label="bbSettingLabel" prop="bbSetting">
					<Tags
						v-model="ruleForm.bbSetting"
						tagsName="bbSetting"
						:disabled="disabled"
						:min="minDefault"
						:max="maxLimit.setting"
						:precision="1"
						:step="0.1"
					/>
				</el-form-item>
				<!-- 德州扑克-前注功能,前注(倍BB) -->
				<template v-if="isTexas">
					<el-form-item
						:label="`${$t('dxn.game_rule.ante_switch')}`"
						class="is-required"
					>
						<el-switch
							v-model="ruleForm.anteSwitch"
							:disabled="disabled"
							:active-value="1"
							:inactive-value="0"
							@change="anteSwitchChange"
						></el-switch>
					</el-form-item>
					<el-form-item
						:label="
							`${$t('dxn.game_rule.ante_limits')}（${unitLabel}）`
						"
						prop="anteLimits"
					>
						<Tags
							v-model="ruleForm.anteLimits"
							tagsName="anteLimits"
							:disabled="disabled"
							:precision="1"
							:step="0.1"
							:min="0"
							:switchVal="ruleForm.anteSwitch"
						/>
					</el-form-item>
					<el-form-item
						label="强制抓（Straddle）1人"
						class="is-required"
					>
						<el-switch
							v-model="ruleForm.straddleSwitch"
							:disabled="disabled"
							:active-value="2"
							:inactive-value="1"
						></el-switch>
					</el-form-item>
				</template>
			</div>
			<div class="show-panel">
				<span class="title" style="width: 120px;">带入带出配置</span>
				<!-- 德州默认带入值（倍BB）短牌默认带入值（倍Ante） -->
				<!-- 德州带入上下限（倍BB）短牌带入上下限（倍Ante） -->
				<el-form-item
					:label="
						`${$t('dxn.game_rule.default_setting')}（${unitLabel}）`
					"
					prop="bbDefaultCarry"
				>
					<Tags
						v-model="ruleForm.bbDefaultCarry"
						tagsName="bbDefaultCarry"
						:disabled="disabled"
						:min="minDefault"
					/>
				</el-form-item>
				<!-- 强制补码 默认0 1关 2开 -->
				<el-form-item class="is-required">
					<span slot="label">
						强制补码:
						<el-popover
							placement="top-start"
							width="auto"
							trigger="hover"
							content="玩家筹码低于此值时，必须补码，否则无法参与下手"
						>
							<span slot="reference">
								<i class="el-icon-question"></i>
							</span>
						</el-popover>
					</span>
					<el-switch
						v-model="ruleForm.forceComplementSwitch"
						:disabled="disabled"
						:active-value="2"
						:inactive-value="1"
					></el-switch>
				</el-form-item>
				<!-- 德州补码上下限（倍BB）短牌补码上下限（倍Ante）-->
				<!-- :max="maxLimit.complementLimit" -->
				<!-- <div class="limit">
						<el-form-item
							:label="
								`${$t(
									'dxn.game_rule.complement_limit'
								)}（${unitLabel}）`
							"
							prop="complementLowerLimit"
						>
							<el-input-number
								v-model.number="ruleForm.complementLowerLimit"
								:min="minDefault"
								:step="1"
								step-strictly
								:controls="false"
								:disabled="disabled"
								:placeholder="
									`${$t('dxn.game_rule.lower_limit_placeholder')}`
								"
								v-input="{ name: 'int' }"
							></el-input-number>
						</el-form-item>
						<el-form-item class="upper-label">≤X≤</el-form-item>
						<el-form-item
							:label="``"
							prop="complementUpperLimit"
							class="upper-label"
						>
							<el-input-number
								v-model.number="ruleForm.complementUpperLimit"
								:min="minDefault"
								:step="1"
								step-strictly
								:controls="false"
								:disabled="disabled"
								:placeholder="
									`${$t('dxn.game_rule.upper_limit_placeholder')}`
								"
								v-input="{ name: 'int' }"
							></el-input-number>
						</el-form-item>
					</div> -->
				<!-- 允许主动带出 0-关闭 1-开启 默认关闭 -->
				<el-form-item
					:label="`${$t('dxn.game_rule.allow_active_bringout')}`"
					class="is-required"
				>
					<el-switch
						v-model="ruleForm.activeBringOut"
						:disabled="disabled"
						:active-value="1"
						:inactive-value="0"
					></el-switch>
				</el-form-item>
				<!-- 必要保留筹码 多个用逗号隔开 不支持小数 -->
				<el-form-item prop="mustKeepChip">
					<span slot="label">
						{{
							`${$t(
								'dxn.game_rule.need_retain_chips'
							)}（${unitLabel}）:`
						}}
						<el-popover
							placement="top-start"
							width="280"
							trigger="hover"
							:content="
								$t('dxn.game_rule.need_retain_chips_tips')
							"
						>
							<span slot="reference">
								<i class="el-icon-question"></i>
							</span>
						</el-popover>
					</span>
					<Tags
						v-model="ruleForm.mustKeepChip"
						tagsName="mustKeepChip"
						:disabled="disabled"
						:step="1"
						:min="0"
						:max="maxMustKeepChip"
					/>
				</el-form-item>
				<!-- 强制带出 默认0 1关 2开 -->
				<el-form-item class="is-required">
					<span slot="label">
						强制带出:
						<el-popover
							placement="top-start"
							width="auto"
							trigger="hover"
							content="玩家筹码超出此值时，强制带出超出部分"
						>
							<span slot="reference">
								<i class="el-icon-question"></i>
							</span>
						</el-popover>
					</span>
					<el-switch
						v-model="ruleForm.forceOutSwitch"
						:disabled="disabled"
						:active-value="2"
						:inactive-value="1"
					></el-switch>
				</el-form-item>
			</div>
			<div class="show-panel">
				<span class="title" style="width: 80px;">基础配置</span>
				<!-- 时长（h) -->
				<el-form-item
					:label="`${$t('dxn.game_rule.duration')}`"
					prop="gameTimes"
				>
					<Tags
						v-model="ruleForm.gameTimes"
						tagsName="gameTimes"
						:disabled="disabled"
						:min="0"
						:max="maxLimit.gameTimes"
						:step="0.1"
						:precision="1"
					/>
				</el-form-item>
				<!-- 人数 -->
				<el-form-item
					:label="`${$t('dxn.game_rule.people')}`"
					prop="gamePeopleNumbers"
				>
					<Tags
						v-model="ruleForm.gamePeopleNumbers"
						:disabled="disabled"
						:min="minPeople"
						:max="maxPeople"
					/>
				</el-form-item>
				<!-- 自动开始人数 -->
				<el-form-item
					:label="`${$t('dxn.game_rule.people_auto_start')}`"
					prop="autoStartNumbers"
				>
					<Tags
						v-model="ruleForm.autoStartNumbers"
						:disabled="disabled"
						:min="minPeople"
						:max="maxPeople"
					/>
				</el-form-item>
				<!-- 每手牌有效底池抽水比例(%) -->
				<!-- :max="maxLimit.rake" -->
				<!-- <el-form-item
					:label="`${$t('dxn.game_rule.pool_pump_ratio')}`"
					prop="rake"
				>
					<el-input-number
						v-model.number="ruleForm.rake"
						:min="0.0"
						:precision="2"
						:step="0.01"
						step-strictly
						:controls="false"
						:disabled="disabled"
						:placeholder="
							`${$t('dxn.game_rule.pool_pump_ratio_placeholder')}`
						"
						v-input="{ name: 'float', num: '2' }"
					></el-input-number>
				</el-form-item> -->
			</div>
			<div class="show-panel">
				<span class="title" style="width: 80px;">保险配置</span>
				<!-- 保险模式 -->
				<el-form-item :label="`${$t('dxn.game_rule.insure_mode')}`">
					<el-checkbox-group
						v-model="insuranceModeArr"
						:disabled="disabled"
					>
						<el-checkbox label="0" :disabled="true" :checked="true">
							不开保险
						</el-checkbox>
						<el-checkbox label="1">
							经典保险
						</el-checkbox>
						<el-checkbox label="2">
							EV保险
						</el-checkbox>
					</el-checkbox-group>
				</el-form-item>
				<!-- 保险触发下限 -->
				<el-form-item prop="insuranceLowerMulti">
					<span slot="label">
						{{
							`${$t(
								'dxn.game_rule.insure_trigger_lower'
							)}（${unitLabel}）:`
						}}
						<el-popover
							placement="top-start"
							width="280"
							trigger="hover"
							:content="
								$t('dxn.game_rule.insure_trigger_lower_tips')
							"
						>
							<span slot="reference">
								<i class="el-icon-question"></i>
							</span>
						</el-popover>
					</span>
					<Tags
						v-model="ruleForm.insuranceLowerMulti"
						tagsName="insuranceLowerMulti"
						:disabled="disabled"
						:min="0"
						:max="999"
					/>
				</el-form-item>
				<!-- EV提取下限 -->
				<el-form-item prop="evExtractionLowerLimitMulti">
					<span slot="label">
						EV提取下限{{ `（${unitLabel}）` }}:
						<el-popover
							placement="top-start"
							width="auto"
							trigger="hover"
							content="玩家的EV大于等于下限时，才可以购买EV保险(提取EV)"
						>
							<span slot="reference">
								<i class="el-icon-question"></i>
							</span>
						</el-popover>
					</span>
					<Tags
						v-model="ruleForm.evExtractionLowerLimitMulti"
						tagsName="evExtractionLowerLimitMulti"
						:disabled="disabled"
						:min="0"
						:max="999"
					/>
				</el-form-item>
				<!-- 短牌底池人数上限 -->
				<el-form-item class="is-required">
					<span slot="label">
						单底池参与人数上限:
						<el-popover
							placement="top-start"
							width="auto"
							trigger="hover"
							content="底池人数超过上限值，不能触发保险"
						>
							<span slot="reference">
								<i class="el-icon-question"></i>
							</span>
						</el-popover>
					</span>
					<el-checkbox-group
						v-model="bottomPoolPeopleArr"
						:disabled="disabled"
					>
						<el-checkbox
							v-for="(item, key) in bottomPoolPeopleList"
							:key="key"
							:label="item"
						>
							{{ item }}
						</el-checkbox>
					</el-checkbox-group>
				</el-form-item>
				<!-- 多池购保 默认0 1开 2关 -->
				<el-form-item class="is-required">
					<span slot="label">
						单底池领先人数上限:
						<el-popover
							placement="top-start"
							width="auto"
							trigger="hover"
						>
							<div>
								单底池领先人数小于等于上限时，才会触发保险。
							</div>
							<div>
								例：配置为3，当底池2个人同时领先，则此底池可触发保险；
							</div>
							<div>当底池4个人同时领先，此底池不触发保险；</div>
							<span slot="reference">
								<i class="el-icon-question"></i>
							</span>
						</el-popover>
					</span>
					<el-select
						v-model="ruleForm.singleBottomPoolLeaderLimit"
						:disabled="disabled"
						style="width:120px;"
					>
						<el-option
							v-for="item in singleBottomPoolLeaderLimitList"
							:key="item"
							:label="item"
							:value="item"
						></el-option>
					</el-select>
				</el-form-item>
				<!-- 多池购保 默认0 1开 2关 -->
				<el-form-item class="is-required">
					<span slot="label">
						{{ `${$t('dxn.game_rule.multi_pool_switch')}:` }}
						<el-popover
							placement="top-start"
							width="250"
							trigger="hover"
						>
							<div>开启：可购买多个领先底池的保险</div>
							<div>关闭：购买领先的最大底池的保险</div>
							<span slot="reference">
								<i class="el-icon-question"></i>
							</span>
						</el-popover>
					</span>
					<el-switch
						v-model="ruleForm.multiPoolSwitch"
						:disabled="disabled"
						:active-value="2"
						:inactive-value="1"
					></el-switch>
				</el-form-item>
				<!-- River保险可买平分Outs开关 默认0 1关 2开 -->
				<el-form-item class="is-required">
					<span slot="label">
						River保险可买平分Outs:
						<el-popover
							placement="top-start"
							width="auto"
							trigger="hover"
							content="Turn轮购买River保险时，是否能购买平分Outs"
						>
							<span slot="reference">
								<i class="el-icon-question"></i>
							</span>
						</el-popover>
					</span>
					<el-switch
						v-model="ruleForm.riverInsuranceSplitOutsSwitch"
						:disabled="disabled"
						:active-value="2"
						:inactive-value="1"
					></el-switch>
				</el-form-item>
				<!-- turn购买保险最低值 -->
				<!-- :max="maxLimit.insuranceTurn" -->
				<el-form-item
					:label="
						`${$t('dxn.game_rule.turn_buy_insure_min_num')}(底池%)`
					"
					prop="insuranceTurn"
				>
					<Tags
						v-model="ruleForm.insuranceTurn"
						tagsName="insuranceTurn"
						:precision="2"
						:disabled="disabled"
						:step="0.01"
						:min="0"
						:max="maxLimit.insuranceTurn"
					/>
				</el-form-item>
			</div>
			<div class="show-panel">
				<span class="title" style="width: 80px;">收费配置</span>
				<!-- 局服务费 1-关闭 2-开启 默认0 -->
				<el-form-item class="is-required">
					<span slot="label">
						{{ `${$t('dxn.game_rule.table_fee_switch')}:` }}
						<el-popover
							placement="top-start"
							width="330"
							trigger="hover"
							:content="$t('dxn.game_rule.table_fee_tips')"
						>
							<span slot="reference">
								<i class="el-icon-question"></i>
							</span>
						</el-popover>
					</span>
					<el-switch
						v-model="ruleForm.tableFeeSwitch"
						:disabled="disabled"
						:active-value="2"
						:inactive-value="1"
					></el-switch>
				</el-form-item>
				<!-- 局服务费比例(%)，两位小数 -->
				<el-form-item
					:label="`${$t('dxn.game_rule.table_fee')}`"
					prop="tableFeeScale"
				>
					<Tags
						v-model="ruleForm.tableFeeScale"
						tagsName="tableFeeScale"
						:disabled="disabled"
						:step="0.01"
						:precision="2"
						:min="0"
						:max="maxLimit.tableFeeScale"
					/>
				</el-form-item>
				<!-- 每手服务费，0-关闭 1-按底池比例 2-按盈利比例 3-都选择 -->
				<el-form-item class="is-required">
					<span slot="label">
						{{ `${$t('dxn.game_rule.hand_service_charge')}:` }}
						<el-popover
							placement="top-start"
							width="280"
							trigger="hover"
							:content="
								$t('dxn.game_rule.hand_service_charge_tips')
							"
						>
							<span slot="reference">
								<i class="el-icon-question"></i>
							</span>
						</el-popover>
					</span>
					<el-checkbox-group
						v-model="serviceChargeArr"
						:disabled="disabled"
					>
						<el-checkbox
							v-for="(item, key) in serviceChargeTypeArr"
							:key="key"
							:label="item.code"
						>
							{{ item.description }}
						</el-checkbox>
					</el-checkbox-group>
				</el-form-item>
				<!-- 按底池比例收费% 多个用逗号隔开 支持小数 -->
				<el-form-item
					:label="`${$t('dxn.game_rule.pool_ratio_charge')}`"
					prop="bottomPoolFee"
				>
					<Tags
						v-model="ruleForm.bottomPoolFee"
						tagsName="bottomPoolFee"
						:disabled="disabled"
						:step="0.01"
						:precision="2"
						:min="0"
						:max="maxLimit.bottomPoolFee"
					/>
				</el-form-item>
				<!-- 盈利比例收费(%)多个用逗号隔开  支持小数 -->
				<el-form-item
					:label="`${$t('dxn.game_rule.profit_ratio_charge')}`"
					prop="profitFee"
				>
					<Tags
						v-model="ruleForm.profitFee"
						tagsName="profitFee"
						:disabled="disabled"
						:step="0.01"
						:precision="2"
						:min="0"
						:max="maxLimit.profitFee"
					/>
				</el-form-item>
				<!-- 低于三人五折 默认0 1关 2开 -->
				<el-form-item class="is-required">
					<span slot="label">
						低于三人五折:
						<el-popover
							placement="top-start"
							width="auto"
							trigger="hover"
						>
							<div>
								手牌参与玩家少于三人，按收费比例*0.5收取手牌服务费；
							</div>
							<div>
								手牌参与玩家大于等于三人，按收费比例收取手牌服务费。
							</div>
							<div>关闭：按收费比例收取手牌服务费。</div>
							<span slot="reference">
								<i class="el-icon-question"></i>
							</span>
						</el-popover>
					</span>
					<el-switch
						v-model="ruleForm.halfDiscountSwitch"
						:disabled="disabled"
						:active-value="2"
						:inactive-value="1"
					></el-switch>
				</el-form-item>
				<!-- PreFlop结束免费开关 0-没有配置 1-关闭，2-开启 (默认开启) -->
				<el-form-item class="is-required">
					<span slot="label">
						PreFlop结束免费:
						<el-popover
							placement="top-start"
							width="auto"
							trigger="hover"
							content="手牌在PreFlop轮结束，不收取手牌服务费"
						>
							<span slot="reference">
								<i class="el-icon-question"></i>
							</span>
						</el-popover>
					</span>
					<el-switch
						v-model="ruleForm.preflopEndFreeSwitch"
						:disabled="disabled"
						:active-value="2"
						:inactive-value="1"
					></el-switch>
				</el-form-item>
				<!-- 每手收费上限, 多个用逗号隔开 支持小数 -1代表无上限 -->
				<el-form-item prop="feeCap" class="is-required">
					<span slot="label">
						{{
							`${$t(
								'dxn.game_rule.hand_charge_limit'
							)}（${unitLabel}）:`
						}}
						<el-popover
							placement="top-start"
							width="180"
							trigger="hover"
							content="每手牌的收费上限"
						>
							<span slot="reference">
								<i class="el-icon-question"></i>
							</span>
						</el-popover>
					</span>

					<Tags
						v-model="ruleForm.feeCap"
						tagsName="feeCap"
						:disabled="disabled"
						:step="0.01"
						:precision="2"
						:min="0"
					/>
					<span>
						<el-checkbox
							v-model="feeCapNoLimit"
							:key="Math.random()"
							true-label="-1"
							false-label="0"
							:disabled="disabled"
						>
							无上限
						</el-checkbox>
					</span>
				</el-form-item>
			</div>
			<div class="show-panel">
				<span class="title" style="width: 60px;">防作弊</span>
				<!-- 抽签入座 0-默认（没有配置） 1-关闭，2-开启 -->
				<el-form-item label="抽签入座" class="is-required">
					<el-switch
						v-model="ruleForm.drawLotsSeatingSwitch"
						:disabled="disabled"
						:active-value="2"
						:inactive-value="1"
					></el-switch>
				</el-form-item>
				<!-- Preflop延迟看牌 0-关闭 1-开启 默认关闭 -->
				<el-form-item label="Preflop延迟看牌" class="is-required">
					<el-switch
						v-model="ruleForm.preflopDelay"
						:disabled="disabled"
						:active-value="1"
						:inactive-value="0"
					></el-switch>
				</el-form-item>
				<!-- 实时视频 0-默认（没有配置） 1-关闭，2-开启 -->
				<el-form-item label="实时视频" class="is-required">
					<el-switch
						v-model="ruleForm.realTimeVideoSwitch"
						:disabled="disabled"
						:active-value="2"
						:inactive-value="1"
					></el-switch>
				</el-form-item>
				<!-- GPS限制 0-默认（没有配置） 1-关闭，2-开启 -->
				<el-form-item label="GPS限制" class="is-required">
					<el-switch
						v-model="ruleForm.gpsImposeSwitch"
						:disabled="disabled"
						:active-value="2"
						:inactive-value="1"
					></el-switch>

					<el-form-item
						prop="limitToLessThan"
						style="display: inline-block;margin-left:50px;"
					>
						限制范围小于
						<el-input
							v-model="ruleForm.limitToLessThan"
							v-input="{ name: 'intp' }"
							:disabled="
								disabled || ruleForm.gpsImposeSwitch !== 2
							"
							style="width: 100px;"
							:maxlength="6"
						></el-input>
						米
					</el-form-item>
				</el-form-item>
				<!-- IP限制 0-默认（没有配置） 1-关闭，2-开启 -->
				<el-form-item label="IP限制" class="is-required">
					<el-switch
						v-model="ruleForm.ipImposeSwitch"
						:disabled="disabled"
						:active-value="2"
						:inactive-value="1"
					></el-switch>
				</el-form-item>
				<!-- 仅IOS设备 0-默认（没有配置） 1-关闭，2-开启 -->
				<el-form-item label="仅IOS设备" class="is-required">
					<el-switch
						v-model="ruleForm.onlyIosDeviceSwitch"
						:disabled="disabled"
						:active-value="2"
						:inactive-value="1"
					></el-switch>
				</el-form-item>
			</div>
			<div class="show-panel">
				<span class="title" style="width: 80px;">其他配置</span>
				<!-- 语音聊天 0-关闭 1-开启 默认0 -->
				<el-form-item
					:label="`${$t('dxn.game_rule.voice_chat_switch')}`"
					class="is-required"
				>
					<el-switch
						v-model="ruleForm.voiceChatSwitch"
						:disabled="disabled"
						:active-value="1"
						:inactive-value="0"
					></el-switch>
				</el-form-item>
				<!-- 实时语音 0-默认（没有配置） 1-关闭，2-开启 -->
				<el-form-item label="实时语音" class="is-required">
					<el-switch
						v-model="ruleForm.realTimeVoiceSwitch"
						:disabled="disabled || ruleForm.voiceChatSwitch !== 1"
						:active-value="2"
						:inactive-value="1"
					></el-switch>
				</el-form-item>
				<!-- 隐藏小数 0-关闭 1-开启 默认开启 -->
				<el-form-item
					:label="`${$t('dxn.game_rule.hide_decimals')}`"
					class="is-required"
				>
					<el-switch
						v-model="ruleForm.hideDecimals"
						:disabled="disabled"
						:active-value="1"
						:inactive-value="0"
					></el-switch>
				</el-form-item>
				<!-- 仅直属会员可见 0-关闭 1-开启 默认0 -->
				<el-form-item
					:label="`${$t('dxn.game_rule.only_direct_member_switch')}`"
					class="is-required"
				>
					<el-switch
						v-model="ruleForm.onlyDirectMemberSwitch"
						:disabled="disabled"
						:active-value="1"
						:inactive-value="0"
					></el-switch>
				</el-form-item>
				<!-- 入桌密码 0-关闭 1-开启 默认0 -->
				<el-form-item
					:label="`${$t('dxn.game_rule.table_entry_password')}`"
					class="is-required"
				>
					<el-switch
						v-model="ruleForm.tableEntryPasswordSwitch"
						:disabled="disabled"
						:active-value="1"
						:inactive-value="0"
					></el-switch>
				</el-form-item>
				<!-- 单次行动延时次数,自然数 -->
				<el-form-item label="单次行动延时次数">
					<Tags
						v-model="singleActionDelaysNumbers"
						tagsName="singleActionDelaysNumbers"
						:disabled="disabled"
						:min="-1"
					/>
				</el-form-item>
				<!-- ALLIN展示OUTS与胜率 0-关闭 1-开启 -->
				<el-form-item
					:label="`${$t('dxn.game_rule.allin_outs_win_rate')}`"
					class="is-required"
				>
					<el-switch
						v-model="ruleForm.showOutsWinn"
						:disabled="disabled"
						:active-value="1"
						:inactive-value="0"
					></el-switch>
				</el-form-item>
				<!-- 付费看以往手牌开关 0-没有配置 1-关闭，2-开启 (默认开启) -->
				<el-form-item class="is-required">
					<span slot="label">
						付费看以往手牌:
						<el-popover
							placement="top-start"
							width="auto"
							trigger="hover"
							content="玩家可以付费看一手牌中单个玩家手牌，费用根据底池计算"
						>
							<span slot="reference">
								<i class="el-icon-question"></i>
							</span>
						</el-popover>
					</span>
					<el-switch
						v-model="ruleForm.paySeePastHandSwitch"
						:disabled="disabled"
						:active-value="2"
						:inactive-value="1"
					></el-switch>
				</el-form-item>
			</div>
			<div class="show-panel">
				<span class="title" style="width: 120px;">额外玩法配置</span>
				<el-form-item label="鱿鱼游戏">
					<el-switch
						v-model="ruleForm.squidGameSwitch"
						:disabled="disabled"
						:active-value="2"
						:inactive-value="1"
					></el-switch>
				</el-form-item>
				<el-form-item :label="`奖励值（${unitLabel}）`">
					<Tags
						v-model="ruleForm.rewardValue"
						tagsName="rewardValue"
						:disabled="disabled"
						:min="0"
						:max="99"
					/>
				</el-form-item>
				<el-form-item label="最低人数">
					<Tags
						v-model="ruleForm.minimumPeopleNumber"
						tagsName="minimumPeopleNumber"
						:disabled="disabled"
						:min="2"
						:max="9"
					/>
				</el-form-item>
				<el-form-item label="最大轮次">
					<el-tag style="margin-right: 10px;">无限</el-tag>
					<Tags
						v-model="maximumRoundTags"
						tagsName="maximumRound"
						:disabled="disabled"
						:min="0"
						:max="99"
					/>
				</el-form-item>
				<el-form-item label="触发方式">
					<el-checkbox
						v-model="triggerModeInfinite"
						:disabled="disabled"
					>
						无限触发
					</el-checkbox>
					<div>
						<el-checkbox
							v-model="triggerModeHand"
							:disabled="disabled"
						>
							手数触发
						</el-checkbox>
						<Tags
							v-model="ruleForm.handTriggerNumber"
							tagsName="handTriggerNumber"
							:disabled="disabled"
							:min="0"
							:max="99"
						/>
					</div>
				</el-form-item>
				<el-form-item>
					<span slot="label">
						奖励模式:
						<el-popover
							placement="top-start"
							width="auto"
							trigger="hover"
						>
							<div>
								普通鱿鱼：输家赔付每人1份奖励，赢家不论有几条鱿鱼，都只获得1份奖励
							</div>
							<div>
								无限鱿鱼：赢家每有1条鱿鱼，输家就要多赔付1份奖励
							</div>
							<span slot="reference">
								<i class="el-icon-question"></i>
							</span>
						</el-popover>
					</span>
					<el-checkbox-group
						v-model="rewardModelArr"
						:disabled="disabled"
					>
						<el-checkbox label="0" :disabled="true" :checked="true">
							普通鱿鱼
						</el-checkbox>
						<el-checkbox label="1">
							无限鱿鱼
						</el-checkbox>
					</el-checkbox-group>
				</el-form-item>
				<el-form-item label="鱿鱼上限">
					<el-tag style="margin-right: 10px;">无限</el-tag>
					<Tags
						v-model="squidUpperLimitTags"
						tagsName="squidUpperLimit"
						:disabled="disabled"
						:min="0"
						:max="999"
					/>
				</el-form-item>
				<el-form-item>
					<span slot="label">
						鱿鱼最多者独赢:
						<el-popover
							placement="top-start"
							width="auto"
							trigger="hover"
							content="获得鱿鱼数量最多的玩家，独赢牌桌所有鱿鱼奖励，仅在无限鱿鱼中生效"
						>
							<span slot="reference">
								<i class="el-icon-question"></i>
							</span>
						</el-popover>
					</span>
					<el-switch
						v-model="ruleForm.mostSquidWinsSwitch"
						:disabled="disabled"
						:active-value="2"
						:inactive-value="1"
					></el-switch>
				</el-form-item>
				<el-form-item>
					<span slot="label">
						独赢鱿鱼数下限:
						<el-popover
							placement="top-start"
							width="auto"
							trigger="hover"
							content="单个玩家鱿鱼数超过配置数量时，才会触发鱿鱼最多者独赢规则"
						>
							<span slot="reference">
								<i class="el-icon-question"></i>
							</span>
						</el-popover>
					</span>
					<Tags
						v-model="ruleForm.capotSquidNumberLowerLimit"
						tagsName="capotSquidNumberLowerLimit"
						:disabled="disabled"
						:min="-1"
						:max="999"
					/>
				</el-form-item>
				<el-form-item label="多重奖励">
					<el-switch
						v-model="ruleForm.multipleRewardSwitch"
						:disabled="disabled"
						:active-value="2"
						:inactive-value="1"
					></el-switch>
				</el-form-item>
				<el-form-item label="无动作获胜无鱿鱼">
					<el-switch
						v-model="ruleForm.noActionWinsNoSquidSwitch"
						:disabled="disabled"
						:active-value="2"
						:inactive-value="1"
					></el-switch>
				</el-form-item>
				<el-form-item label="首次获得鱿鱼强制亮牌">
					<el-switch
						v-model="ruleForm.firstSquidForceFlashSwitch"
						:disabled="disabled"
						:active-value="2"
						:inactive-value="1"
					></el-switch>
				</el-form-item>
			</div>
		</el-form>
		<GoogleKeyInput
			:isShowdialog="isShowGoogleKey"
			@getGoogleKey="getGoogleKey($event)"
			@backPrevStep="backPrevStep()"
		></GoogleKeyInput>
	</div>
</template>

<script>
import Tags from '../tags'
import list from '@/mixins/list'
import { rules } from './rules'
import {
	serviceChargeTypeArr,
	serviceChargeMap,
	insuranceModeMap,
	squidTriggerModeArr
} from '@/dict/dxn'
export default {
	components: {
		Tags,
		GoogleKeyInput: () => import('@/components/GoogleKeyInput')
	},
	mixins: [list],
	props: {
		gameTypeId: {
			type: Number,
			default: 0
		},
		bbSettingLabel: {
			type: String,
			default: ''
		},
		unitLabel: {
			type: String,
			default: ''
		},
		unitName: {
			type: String,
			default: ''
		},
		maxLimit: {
			type: Object,
			default: () => {
				return {
					gameOvertime: 0,
					setting: 0,
					defaultCarry: 0,
					complementLimit: 0,
					gameTimes: 0,
					rake: 0,
					clubBringInLimit: 0,
					insuranceTurn: 0,
					bottomPoolFee: 0,
					profitFee: 0,
					tableFeeScale: 0
				}
			}
		}
	},
	data() {
		return {
			minDefault: 0,
			minPeople: 1,
			maxPeople: 9,
			maxMustKeepChip: 0,
			isShowGoogleKey: false,
			loading: false,
			editLoading: false,
			disabled: true,
			ruleForm: {
				gameTypeId: '',
				gameName: '',
				status: '',
				gameOvertime: '',
				bbSetting: '',
				bbDefaultCarry: '',
				complementLowerLimit: '',
				complementUpperLimit: '',
				gameTimes: '',
				gamePeopleNumbers: '',
				autoStartNumbers: '',
				rake: '',
				insuranceLower: '',
				evExtractionLowerLimit: '',
				insuranceTurn: '',
				anteLimits: '',
				mustKeepChip: '',
				serviceCharge: '',
				serviceChargeList: '',
				bottomPoolFee: '',
				profitFee: '',
				feeCap: '',
				tableFeeScale: '',
				anteSwitch: 0,
				preflopDelay: 0,
				showOutsWinn: 0,
				hideDecimals: 0,
				activeBringOut: 0,
				tableEntryPasswordSwitch: 0,
				voiceChatSwitch: 0,
				onlyDirectMemberSwitch: 0,
				multiPoolSwitch: 1,
				tableFeeSwitch: 1,
				drawLotsSeatingSwitch: 1,
				forceOutSwitch: 1,
				forceComplementSwitch: 1,
				halfDiscountSwitch: 1,
				straddleSwitch: 1,
				realTimeVoiceSwitch: 1,
				realTimeVideoSwitch: 1,
				gpsImposeSwitch: 1,
				ipImposeSwitch: 1,
				onlyIosDeviceSwitch: 1,
				riverInsuranceSplitOutsSwitch: 1,
				limitToLessThan: '',
				singleActionDelaysNumber: '',
				bottomPoolPeopleMaximum: '',
				squidGameSwitch: 1,
				rewardValue: '',
				minimumPeopleNumber: '',
				maximumRound: '',
				triggerMode: '',
				handTriggerNumber: '',
				rewardModel: '',
				squidUpperLimit: '',
				insuranceLowerMulti: '',
				evExtractionLowerLimitMulti: '',
				singleBottomPoolLeaderLimit: '',
				noActionWinsNoSquidSwitch: 1,
				firstSquidForceFlashSwitch: 1,
				mostSquidWinsSwitch: 1,
				capotSquidNumberLowerLimit: '',
				multipleRewardSwitch: 1,
				paySeePastHandSwitch: 1,
				preflopEndFreeSwitch: 1
			},
			rewardModelArr: [],
			triggerModeInfinite: false, // 无限触发
			triggerModeHand: false, // 手数触发
			maximumRoundTags: '',
			squidUpperLimitTags: '',
			singleActionDelaysNumbers: '',
			feeCapNoLimit: '0',
			insuranceModeArr: [],
			serviceChargeArr: [],
			bottomPoolPeopleArr: [],
			singleBottomPoolLeaderLimitList: [1, 2, 3, 4],
			serviceChargeMap,
			serviceChargeTypeArr,
			insuranceModeMap,
			squidTriggerModeArr
		}
	},
	computed: {
		rules() {
			return rules(this)
		},
		isTexas() {
			return [1, 3].includes(this.gameTypeId)
		},
		bottomPoolPeopleList() {
			if (this.isTexas) {
				return ['2', '3', '4', '5', '6']
			} else {
				return ['2', '3', '4', '5', '6', '7', '8', '9']
			}
		}
	},
	watch: {
		'ruleForm.bbDefaultCarry': {
			handler(val) {
				if (val) {
					const valArr = val.split(',')
					this.maxMustKeepChip = Number(valArr[valArr.length - 1])
				} else {
					this.maxMustKeepChip = 0
				}
			}
		},
		'ruleForm.voiceChatSwitch': {
			handler(val) {
				if (val === 0) {
					this.ruleForm.realTimeVoiceSwitch = 1
				}
			}
		}
	},
	mounted() {
		this.getDxgameConfigDdetail()
	},
	methods: {
		getDxgameConfigDdetail() {
			this.loading = true
			this.$refs.ruleForm.clearValidate()
			this.$api
				.getDxgameConfigDdetailBend({ id: this.gameTypeId })
				.then((res) => {
					this.loading = false
					const val = res?.data || {}
					this.setRuleFormData(val)
				})
				.catch(() => {
					this.loading = false
				})
		},
		setRuleFormData(val) {
			this.ruleForm = val

			this.ruleForm.anteLimits = val.anteLimits || ''
			this.ruleForm.tableFeeScale = val.tableFeeScale || ''
			this.singleActionDelaysNumbers = val.singleActionDelaysNumber || ''

			this.bottomPoolPeopleArr = val.bottomPoolPeopleMaximum
				? val.bottomPoolPeopleMaximum
						.split(',')
						.filter((item) =>
							this.bottomPoolPeopleList.includes(item)
						)
				: []

			this.serviceChargeArr = val.serviceChargeList
				? val.serviceChargeList.split(',')
				: []
			// 处理保险模式数据结构
			this.insuranceModeArr = val.insuranceMode
				? val.insuranceMode.split(',')
				: []
			// 不开保险为选中并且不可编辑
			if (!this.insuranceModeArr.includes('0')) {
				this.insuranceModeArr.push('0')
			}
			// 处理每手收费上限
			const feeCapArr = val.feeCap ? val.feeCap.split(',') : []
			if (feeCapArr.length === 0) {
				this.feeCapNoLimit = '-1'
			} else if (feeCapArr.indexOf('-1') > -1) {
				feeCapArr.pop()
				this.ruleForm.feeCap = feeCapArr.join(',')
				this.feeCapNoLimit = '-1'
			}

			// 鱿鱼游戏配置处理
			this.maximumRoundTags = val.maximumRound
				? val.maximumRound
						.split(',')
						.filter((item) => item != '-1')
						.join(',')
				: ''
			this.squidUpperLimitTags = val.squidUpperLimit
				? val.squidUpperLimit
						.split(',')
						.filter((item) => item != '-1')
						.join(',')
				: ''
			this.rewardModelArr = val.rewardModel
				? val.rewardModel.split(',')
				: []
			if (!this.rewardModelArr.includes('0')) {
				this.rewardModelArr.push('0')
			}
			const triggerModeArr = val.triggerMode
				? val.triggerMode.split(',')
				: []
			this.triggerModeInfinite = triggerModeArr.includes('0')
			this.triggerModeHand = triggerModeArr.includes('1')

			// 单底池领先人数上限默认值为4
			this.ruleForm.singleBottomPoolLeaderLimit =
				val.singleBottomPoolLeaderLimit || 4
		},
		// 前注功能开启校验
		anteSwitchChange(val) {
			if (val === 1 && this.ruleForm.anteLimits === '') {
				this.$message.closeAll()
				this.$message.warning(this.$t('dxn.game_rule.ante_switch_tips'))
				this.ruleForm.anteSwitch = 0
			}
		},
		// 校验是否获取配置数据
		isGetGameTypeId() {
			if (!this.ruleForm.gameTypeId) {
				this.$message.closeAll()
				this.$message.warning('未获取配置数据，不能保存')
				return false
			}
			return true
		},
		// 修改开关
		handleChangeStatus(val) {
			if (!this.isGetGameTypeId()) {
				return
			}
			this.$confirm(
				`${
					val
						? this.$t('dxn.confirm_start_up')
						: this.$t('dxn.confirm_close')
				}`,
				this.$t('common.components.tip'),
				{
					confirmButtonText: this.$t('common.sure'),
					cancelButtonText: this.$t('common.cancel'),
					type: 'warning'
				}
			)
				.then(() => {
					this.$api
						.dxgameConfigSwitchBend({
							gameTypeId: this.ruleForm.gameTypeId,
							status: val
						})
						.then((res) => {
							if (res.code === 200) {
								this.$message.success(
									val
										? this.$t('dxn.game_rule.open_success')
										: this.$t('dxn.game_rule.close_success')
								)
								this.getDxgameConfigDdetail()
							}
						})
						.catch((e) => {
							this.$message.error(
								e.msg ||
									this.$t('dxn.game_rule.operation_failed')
							)
						})
				})
				.catch(() => {
					this.$message({
						type: 'info',
						message: '已取消'
					})
				})
		},
		// 值校验
		ruleFormValidFlag() {
			this.$message.closeAll()
			if (this.serviceChargeArr.length === 0) {
				this.$message.warning('请选择每手服务费')
				return true
			}
			if (!this.ruleForm.feeCap) {
				this.$message.warning('每手收费上限不能为空')
				return true
			}
			if (!this.ruleForm.tableFeeScale) {
				this.$message.warning('局服务费比例不能为空')
				return true
			}
			if (!this.singleActionDelaysNumbers) {
				this.$message.warning('单次行动延时次数不能为空')
				return true
			}
			if (this.bottomPoolPeopleArr.length === 0) {
				this.$message.warning('底池人数上限至少选择一项')
				return true
			}
			// 鱿鱼游戏开启校验
			if (this.ruleForm.squidGameSwitch === 2) {
				if (!this.ruleForm.rewardValue) {
					this.$message.warning('奖励值不能为空')
					return true
				}
				if (!this.ruleForm.minimumPeopleNumber) {
					this.$message.warning('最低人数不能为空')
					return true
				}
				if (!this.maximumRoundTags) {
					this.$message.warning('最大轮次不能为空')
					return true
				}
				if (!this.triggerModeHand && !this.triggerModeInfinite) {
					this.$message.warning('鱿鱼游戏触发方式不能为空')
					return true
				}
				if (this.triggerModeHand && !this.ruleForm.handTriggerNumber) {
					this.$message.warning(
						'触发方式选择手数触发时，必须增加选项'
					)
					return true
				}
				if (!this.squidUpperLimitTags) {
					this.$message.warning('鱿鱼上限不能为空')
					return true
				}
			}
			return false
		},
		// 点击保存
		handleSubmit() {
			if (!this.isGetGameTypeId()) {
				return
			}
			this.$refs.ruleForm.validate((valid) => {
				if (valid) {
					if (this.ruleFormValidFlag()) {
						return
					}
					this.isShowGoogleKey = true
					this.ruleForm.singleActionDelaysNumber = this.singleActionDelaysNumbers
					this.ruleForm.bottomPoolPeopleMaximum = this.bottomPoolPeopleArr
						.sort()
						.join(',')
					this.ruleForm.serviceChargeList = this.serviceChargeArr
						.sort()
						.join(',')
					this.ruleForm.insuranceMode =
						this.insuranceModeArr.length > 0
							? this.insuranceModeArr.sort().join(',')
							: ''
					// 鱿鱼游戏数据处理
					this.ruleForm.maximumRound = this.maximumRoundTags
					this.ruleForm.squidUpperLimit = this.squidUpperLimitTags
					this.ruleForm.rewardModel = this.rewardModelArr
						.sort()
						.join(',')
					// 触发方式
					const triggerModeArr = []
					if (this.triggerModeInfinite) {
						triggerModeArr.push('0')
					}
					if (this.triggerModeHand) {
						triggerModeArr.push('1')
					}
					this.ruleForm.triggerMode = triggerModeArr.sort().join(',')
				} else {
					return false
				}
			})
		},
		backPrevStep() {
			this.isShowGoogleKey = false
		},
		// 谷歌密钥验证
		getGoogleKey(googleCode) {
			this.ruleForm.googleVerifyCode = googleCode
			const params = Object.assign({}, this.ruleForm)
			// 每手收费上限处理
			const feeCapArr = this.ruleForm.feeCap
				? this.ruleForm.feeCap.split(',')
				: []
			if (this.feeCapNoLimit === '-1') {
				feeCapArr.push('-1')
			}
			params.feeCap = Array.from(new Set(feeCapArr)).join(',')

			params.maximumRound = '-1,' + params.maximumRound
			params.squidUpperLimit = '-1,' + params.squidUpperLimit

			this.isShowGoogleKey = false
			this.setEditLoading(true)
			this.$api
				.dxgameConfigUpdateTexasBend(params)
				.then(() => {
					this.$message.success(
						this.$t('dxn.game_rule.operation_successful')
					)
					this.setEditLoading(false)
					this.disabled = true
					this.getDxgameConfigDdetail()
				})
				.catch(() => {
					this.disabled = false
					this.setEditLoading(false)
				})
		},
		setEditLoading(flag) {
			this.editLoading = flag
			this.$emit('getEditLoading', this.editLoading)
		},
		handleCancel() {
			this.disabled = true
			this.getDxgameConfigDdetail()
		},
		// 编辑
		handleEdit() {
			this.disabled = false
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	::v-deep .el-input-number.is-without-controls .el-input__inner {
		text-align: left;
	}
	.show-ruleForm {
		.flex-box {
			display: flex;
			justify-content: space-between;
			.left {
				display: flex;
			}
		}
		.limit {
			display: flex;
			align-items: center;
			.upper-label {
				margin-left: -150px;
			}
		}
	}
	.show-panel {
		width: 100%;
		padding: 5px;
		border: 1px solid #dcdfe6;
		border-radius: 10px;
		margin-bottom: 30px;
		.title {
			display: block;
			height: 30px;
			position: relative;
			top: -18px;
			text-align: left;
			background: white;
			font-weight: 500;
		}
	}
	.btn-top-fixed {
		position: fixed;
		top: 115px;
		right: 30px;
		z-index: 10;
	}
}
::v-deep .el-icon-question:after {
	font-size: 14px;
	margin-left: -2px;
}
</style>
